//
//  LYLCommonHeaderView.m
//  ONE
//
//  Created by dllo on 16/6/13.
//  Copyright © 2016年 GroupNine. All rights reserved.
//

#import "LYLCommonHeaderView.h"

@interface LYLCommonHeaderView ()

/** 评论数label */
@property (nonatomic, strong) UILabel *commentsCountLabel;

/** 右侧按钮 */
@property (nonatomic, strong) UIButton *rightButton;

@end

@implementation LYLCommonHeaderView
{
    // 头部视图类型
    LYLHeaderViewType viewType;
}

// 头部视图高
+ (CGFloat)headerViewHeight
{
    return 44;
}

- (instancetype)initWithHeaderViewType:(LYLHeaderViewType)type
{
    self = [super init];
    if (self) {
        viewType = type;
        [self createHeaderView];
    }
    return self;
}

#pragma mark --创建头部视图
- (void)createHeaderView
{
    if (viewType == LYLHeaderViewTypeNone || _commentsCountLabel) {
        return;
    }
    
    self.backgroundColor = LYLViewControllerBGColor;
    self.clipsToBounds = YES;
    
    NSString *leftText;
    NSString *rightButtonImageNamePrefix;
    switch (viewType) {
        case LYLHeaderViewTypeNone:
            break;
        case LYLHeaderViewTypeComment:
        {
            leftText = @"评论列表";
//            rightButtonImageNamePrefix = @"review";
            break;
        }
        case LYLHeaderViewTypeRelatedRec:
        {
            leftText = @"相关推荐";
            break;
        }
        case LYLHeaderViewTypeRelatedMusic:
        {
            leftText = @"相似歌曲";
            rightButtonImageNamePrefix = @"music_list_play";
            break;
        }
        case LYLHeaderViewTypeMovieStory:
        {
            leftText = @"电影故事";
            rightButtonImageNamePrefix = @"unofficial_plot";
            break;
        }
        case LYLHeaderViewTypeMovieReview:
        {
            leftText = @"评审团短评";
            break;
        }
        case LYLHeaderViewTypeMovieComment:
        {
            leftText = @"评论列表";
            rightButtonImageNamePrefix = @"moviereview";
            break;
        }
        case LYLHeaderViewTypeScoreRatio:
        {
            leftText = @"分数比例";
            break;
        }
        default:
            break;
    }
    
    // 初始化背景
    UIView *bgView = [UIView new];
    bgView.backgroundColor = LYLLightGrayTextColor;
    bgView.layer.shadowColor = LYLShadowColor.CGColor;
    bgView.layer.shadowOffset = CGSizeZero;
    bgView.layer.shadowRadius = 2;
    bgView.layer.shadowOpacity = 0.1;
    [self addSubview:bgView];
    [bgView makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self).insets(UIEdgeInsetsMake(3, 0, -3, 0));
    }];
    
    // 初始化线条
    UIView *lineView = [UIView new];
    lineView.backgroundColor = LYLSeparatorColor;
    lineView.backgroundColor = [UIColor colorWithWhite:198 / 255.0 alpha:0.5];// #80C6C6C6;
    [bgView addSubview:lineView];
    [lineView makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(0.5);
        make.left.top.right.equalTo(bgView);
    }];
    
    _commentsCountLabel = [UILabel new];
    _commentsCountLabel.text = leftText;
    _commentsCountLabel.textColor = [UIColor colorWithRed:0.57 green:0.57 blue:0.57 alpha:1.00];
    _commentsCountLabel.font = FontWithSize(12);
    [self addSubview:_commentsCountLabel];
    [_commentsCountLabel makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self).insets(UIEdgeInsetsMake(0, 12, 0, 0));
    }];
    
    _rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_rightButton setImage:[UIImage imageNamed:rightButtonImageNamePrefix ? [NSString stringWithFormat:@"%@_normal", rightButtonImageNamePrefix] : nil] forState:UIControlStateNormal];
    [_rightButton setImage:[UIImage imageNamed:rightButtonImageNamePrefix ? [NSString stringWithFormat:@"%@_highlighted", rightButtonImageNamePrefix] : nil] forState:UIControlStateHighlighted];
    [_rightButton addTarget:self action:@selector(didClickedRightButton) forControlEvents:UIControlEventTouchUpInside];
    _rightButton.userInteractionEnabled = rightButtonImageNamePrefix;
    [self addSubview:_rightButton];
    [_rightButton makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.equalTo(44);
        make.right.equalTo(self).offset(-8);
        make.centerY.equalTo(self);
    }];
}

#pragma mark 头侧按钮点击方法
- (void)didClickedRightButton
{
    // DDLogDebug--定义输出调试文本  _cmd--代表本方法selector的名称
    DDLogDebug(@"common header view %@", NSStringFromSelector(_cmd));
}

@end
